﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title></title>

    /// <reference path="wp-includes/js/jquery/jquery-1.8.1.min.js" />
    <script src="wp-includes/js/jquery/jquery-1.8.1.min.js" type="text/javascript"></script>

    <script language="javascript" type="text/javascript">
        function RemoveSpaceLines(advanced) {
            var nLines = 0;
            var nSpaces = 0;

            if (advanced) {
                nLines = parseInt(Text1.value);
                nSpaces = parseInt(Text2.value);

                if (isNaN(nLines) || nLines < 0) nLines = 0;
                else if (nLines > 100) nLines = 100;
                if (isNaN(nSpaces) || nSpaces < 0) nSpaces = 0;
                else if (nSpaces > 100) nSpaces = 100;
            }

            var nls = "";

            for (var i = 0; i < nSpaces; i++) nls += "\n";

            var text = "";
            var index = nLines;
            var arr = TextArea1.value.split('\n');
            for (x in arr) {
                var str = arr[x];
                if (str.length == 0) continue;
                if (str.search(/\S/) >= 0) {
                    index--;
                    text += str + "\n";
                }

                if (index == 0) {
                    text += nls;
                    index = nLines;
                }
            }
            TextArea1.value = text;
        }

        function CreateAdvanceRemoveSpacesLine(ele) {
        
            alert($("#div_advanced").tagName);
            //$("div_advanced").innerHTML += "每<input id=\"Text1\" type=\"text\" class=\"inputText\" value=\"1\" />行文字后跟随<input id=\"Text2\" type=\"text\" class=\"inputText\" value=\"1\" />行空白<input type=\"button\" value=\"执行\" onclick=\"RemoveSpaceLines(true)\" />";
        }
    </script>

</head>
<body>
    <p>
        <span>空白行处理:&nbsp;&nbsp;&nbsp;</span><a href="javascript:RemoveSpaceLines();">消除空白行</a>
        <a href="javascript:;" onclick="CreateAdvanceRemoveSpacesLine(this);">高级</a>
    </p>
    <div id="div_advanced" style="height:12px;">
    </div>
    <p>
        <textarea id="TextArea1"></textarea></p>
</body>
</html>
